<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
       <button>获取天气</button>
       <hr>
       <div></div>
</body>
</html>
<script src='./lib/jquery.min.js'></script>
<script >
    
    $(()=>{
       $("button").click(()=>{
           $.ajax({
               type:"get",
               url:"https://restapi.amap.com/v3/weather/weatherInfo",
               data:{
                   "key":"870b5c1f68f4da5c854d7348a8e2ff3d",
                   "city":"绵阳市",
                   "extensions":"all"
               },
               dataType:"jsonp",
               success(data){
                     console.log(data);
                let str ='';
                let cast = data.forecasts[0].casts;
                 //遍历数组 i 索引，obj 别名
                 $.each(cast,(i,obj)=>{
               str+=`时间：${obj.date},天气:${obj.dayweather},白天温度：${obj.daytemp}℃,夜间温度:${obj.nighttemp}℃<br/>`;
                 });

                 $("div").html(str);
  
               }
           });
       }) 
    });


</script>